package com.BigDate.server.controller;


import com.BigDate.server.pojo.ForkExp;
import com.BigDate.server.pojo.User;
import com.BigDate.server.service.IForkExpService;
import com.BigDate.server.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author stx
 * @since 2021-12-22
 */
@RestController
@RequestMapping("/fork-exp")
public class ForkExpController {

    @Autowired
    private IForkExpService expService;
    @Autowired
    private IUserService userService;

    @ApiOperation(value = "展示fork记录")
    @GetMapping("/{expId}")
    public List<ForkExp> getForkExp(@PathVariable("expId") Integer expId){
        List<ForkExp> list = expService.list(new QueryWrapper<ForkExp>().eq("expid",expId));
        for (ForkExp forkExp : list) {
            User user = userService.getById(forkExp.getUserid());
            forkExp.setNickname(user.getNickname());
        }
        return list;
    }
}
